from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from Until.ParseConfigFile import ParserConfigFile
from Until.until import find_element


class RegisterPage:

    def __init__(self,wd):
        self.wd = wd
        self.parse = ParserConfigFile()
        self.registerLocation = self.parse.getSection('freshMarketRegister')

    def click_registerButton(self):
        '''
        点击会员注册
        :return:
        '''
        try:
            register_type,expression = self.registerLocation['register_page.registerclilk'].split(':')
            find_element(self.wd,register_type,expression).click()
        except Exception as e:
            raise e


    def input_username(self,username):
        '''
        输入注册用户名
        :param username:
        :return:
        '''
        try:
            register_type,expression = self.registerLocation['register_page.username'].split(':')
            find_element(self.wd,register_type,expression).send_keys(username)
        except Exception as e:
            raise e

    def input_email(self,email):
        '''
        输入注册邮箱
        :param email:
        :return:
        '''
        try:
            register_type,expression = self.registerLocation['register_page.email'].split(':')
            find_element(self.wd,register_type,expression).send_keys(email)
        except Exception as e:
            raise e

    def input_password(self,password):
        '''
        输入注册密码
        :param password:
        :return:
        '''
        try:
            register_type,expression = self.registerLocation['register_page.password'].split(':')
            find_element(self.wd,register_type,expression).send_keys(password)
        except Exception as e:
            raise e


    def input_conform_password(self,conformPassword):
        '''
        二次输入注册密码
        :param conformPassword:
        :return:
        '''
        try:
            register_type,expression = self.registerLocation['register_page.conform_password'].split(':')
            find_element(self.wd,register_type,expression).send_keys(conformPassword)
        except Exception as e:
            raise e

    def input_phoneNumber(self,phoneNumber):
        '''
        输入注册手机号
        :param phoneNumber:
        :return:
        '''
        try:
            register_type,expression = self.registerLocation['register_page.phonenumber'].split(':')
            find_element(self.wd,register_type,expression).send_keys(phoneNumber)
        except Exception as e:
            raise e

    def clickSubmit(self):
        '''
        点击提交按钮
        :return:
        '''
        try:
            register_type,expression = self.registerLocation['register_page.submitbutton'].split(':')
            find_element(self.wd,register_type,expression).click()
        except Exception as e:
            raise e


if __name__ == '__main__':
    chromeDriver_path = 'E:\Python\chromedriver.exe'
    options = Options()
    options.add_argument('--start-maximized')
    wd = webdriver.Chrome(executable_path=chromeDriver_path, options=options)
    wd.get('http://www.cherryzqr.top/fsmarket/index.php')

    register = RegisterPage(wd)
    register.click_registerButton()
    register.input_username('cheyyr2')
    register.input_email('13333333333@163.com')
    register.input_password('A123456')
    register.input_conform_password('A123456')
    register.input_phoneNumber('13333333333')
    register.clickSubmit()